/**
 * 
 */
package controller;

import java.util.List;

import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;

import model.User;

import dao.UserDAO;

/**
 * @author jlucasps
 *
 */
@Resource
public class UserController {

	private UserDAO userDAO;
	private Result result;
	
	public UserController(UserDAO userDAO, Result result) {
		this.userDAO = userDAO;
		this.result = result;
	}

	public void form() {
	}

	public void save(User user){
		this.userDAO.save(user);
		result.redirectTo(UserController.class).list();
	}

	public User load(Long id) {
		return this.userDAO.load(id);
	}
	
	public void update(User user) {
		this.userDAO.update(user);
		this.result.redirectTo(UserController.class).list();
	}
	
	public void delete(Long id) {
		this.userDAO.delete(this.userDAO.load(id));
		this.result.redirectTo(UserController.class).list();
	}
	
	public List<User> list(){
		return this.userDAO.list();
	}
}
